package model;

import java.util.Objects;


public abstract class Resource {
    private final String id;
    private final String title;
    private boolean available;


    public Resource(String id, String title) {
        this.id = id;
        this.title = title;
        this.available = true; // 默认可用
    }


    public String getId() {
        return id;
    }


    public String getTitle() {
        return title;
    }


    public boolean isAvailable() {
        return available;
    }


    public void setAvailable(boolean available) {
        this.available = available;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Resource resource = (Resource) o;
        return id.equals(resource.id);
    }


    @Override
    public int hashCode() {
        return Objects.hash(id);
    }


    @Override
    public String toString() {
        return String.format("%s [ID: %s, Title: %s, Available: %b]",
                this.getClass().getSimpleName(), id, title, available);
    }


    public static java.util.List<Resource> getSampleResources() {
        java.util.List<Resource> resources = new java.util.ArrayList<>();
        resources.add(new Book("B001", "Java编程思想", "Bruce Eckel"));
        resources.add(new Magazine("M001", "计算机世界", "2023-09"));
        resources.add(new DVD("D001", "Java教程", 120));
        resources.add(new Book("B002", "设计模式", "Erich Gamma"));
        resources.add(new Magazine("M002", "程序员杂志", "2023-10"));
        resources.add(new DVD("D002", "Spring实战", 90));
        return resources;
    }
}

